;
(function (call) {
    var main = {
        mapId: "tjMap",
        productList: [
            { proId: 'UV,TMP,RH,W', name: '风温湿ω', selected: true, className: 'productName', height: '100,150,200,250,300,400,500,700,850,1000' },
            { proId: 'UV,TMP,Q,W', name: '风温比湿ω', selected: false, className: 'productName', height: '100,150,200,250,300,400,500,700,850,1000' },
            { proId: 'UV,WS', name: '风', selected: false, className: 'productName', height: '100,150,200,250,300,400,500,700,850,1000' },
        ],
        cityListCfg: [
            { name: '市区', x: '117.200', y: '39.070' },
            { name: '宝坻区', x: '117.343', y: '39.622' },
            { name: '北辰区', x: '117.127', y: '39.278' },
            { name: '滨海新区', x: '117.613', y: '39.109' },
            { name: '东丽区', x: '117.361', y: '39.137' },
            { name: '蓟州区', x: '114.516', y: '39.647' },
            { name: '津南区', x: '117.372', y: '38.918' },
            { name: '静海区', x: '116.931', y: '38.903' },
            { name: '宁河区', x: '117.731', y: '39.392' },
            { name: '武清区', x: '117.027', y: '39.418' },
            { name: '西青区', x: '116.984', y: '39.153' }
        ],
        router: {
            timeProfile: '/drawmake/makeprofile/timeProfile',
        },
        init: function () {
            this.initDatePicker();
            this.initPointData();
            this.initProduct();
            this.bindEvt();
        },
        // 初始化时间控件
        initDatePicker: function () {
            var that = this;
            var time = $("#modal_point_pro").data('time');
            that.datepicker = CafeJS.Datepicker({
                curDate: time,
                appendTo: "#pointProfile-datepicker",
                dateFmt: "yyyy-MM-dd",
                type: 5,
                timeInterval: 12,
                dateType: 'H',
                customHm: [8, 20],
                call: function () {
                    that.getPointData();
                },
            });
        },
        // 初始化点剖页面基本信息
        initPointData: function () {
            var that = this;
            var x = $("#modal_point_pro").data('x');
            var y = $("#modal_point_pro").data('y');
            $(".lonWrap input").val(x);
            $(".latWrap input").val(y);
            var $city = $(".city-tab");
            that.cityListCfg.forEach(function (item) {
                var $item = $(`<div>${item.name}</div>`)
                $item.data('item', item);
                $city.append($item);
            })
        },
        //初始化类型
        initProduct: function () {
            var that = this;
            var $product = $('.vrm-items');
            that.productList.forEach(function (item) {
                if (item.selected) {
                    var div = '<div class="active ' + item.className + '">' + item.name + '</div>'
                } else {
                    var div = '<div class="' + item.className + '">' + item.name + '</div>'
                }
                var $div = $(div);
                $div.data('item', item);
                $product.append($div);
            })
        },
        getPointData: function () {
            var that = this;
            var pro = $(".vrm-items div.active").data('item');
            var time = new Date(that.datepicker.getVal()).format('yyyyMMddhhmmss');
            var mode = $(".product-szyb-tab div:first-child div ul li.active").text();
            var x = $(".lonWrap input").val();
            var y = $(".latWrap input").val();
            var agings = $("#postSelect").val();
            var params = {
                time: time,
                mode: mode,
                elements: pro.proId,
                heights: pro.height,
                agings: agings,
                lon: x,
                lat: y,
            }
            loading.add();
            $.get(that.router.timeProfile, params, function (res) {
                loading.remove();
                $(".vrm-bottom-charts").empty().append(`<img src="data:img/png;base64,${res}" id="lineProfileDownLoad" class="lineProfile-imgPath">`)
            })
        },
        downImg: function () {
            var url = $(".vrm-bottom-charts img").attr('src');
            $("#pointImg").attr('href', url);
            $("#pointImg")[0].click();
        },
        bindEvt: function () {
            var that = this;
            $(".vrm-items").on('click', 'div.productName', function () {
                $(this).addClass('active').siblings().removeClass('active')
                that.getPointData();
            })
            $('.download').click(function () {
                that.downImg();
            })
            $(".city-tab").on('click', 'div', function () {
                $(this).addClass('active').siblings().removeClass('active')
                var item = $(this).data('item');
                $(".lonWrap input").val(item.x);
                $(".latWrap input").val(item.y);
                that.getPointData();
            })
            $(".selectBtn").click(function () {
                that.getPointData();
            })
            $("#postSelect").change(function () {
                that.getPointData();
            })
            $(".pointBtn").click(function () {
                //$("#modal_point_pro .close").click();
                $("#modal_point_pro").remove();
                //$(".point").click();
            })
            $('.vrm-items div').eq(0).click();
        }
    };
    if (typeof call === 'function') {
        call(main);
    }
})(function (main) {
    main.init();
});